<script lang="tsx">
/**
 * 采购入库
 */
export default {
  name: "warehouse-purchase"
}
</script>

<script lang="tsx" setup>
import {ref} from "vue"
import {definePageModel, PageModel} from "@/frame/view/layout/page-model/constructor.ts"
import {ElMessage, ElMessageBox} from "element-plus"
import {processRequest} from "@/frame/apis/request"

/**
 * 页面配置
 */
const pageModelRef = ref()
const config = definePageModel<any>({
  url: "/api/WarehousePurchase",
  searchForm: {
    els: [
      {
        eType: 'el-input',
        prop: "cardNo",
        props: {
          placeholder: "流转卡号",
          clearable: true
        }
      },
      {
        eType: 'el-input',
        prop: "goods",
        props: {
          placeholder: "物料名称",
          clearable: true
        }
      },
      {
        eType: 'el-input',
        prop: "supplier",
        props: {
          placeholder: "供应商",
          clearable: true
        }
      }
    ]
  },
  table: {
    page: {
      enable: true,
      pageSize: 20
    },
    props: {
      stripe: false,
      border: false
    },
    operation: {
      width: 80,
      props: {
        fixed: "left"
      },
      els: [
        {
          eType: "el-button",
          label: "入库",
          event: "store",
          props: {
            type: "primary",
            link: true
          },
          hide(data: any) {
            if (data.numberStore > 0) {
              return true
            }
            return false
          }
        }
      ]
    },
    els: [
      {
        label: "流转卡号",
        prop: "cardNo",
        minWidth: 120
      },
      {
        label: "物料编码",
        prop: "goodsCode",
        minWidth: 120
      },
      {
        label: "物料名称",
        prop: "goodsName",
        minWidth: 120
      },
      {
        label: "物料规格",
        prop: "goodsSpec",
        minWidth: 120
      },
      {
        label: "物料单位",
        prop: "goodsUnit",
        minWidth: 120
      },
      {
        label: "物料描述",
        prop: "goodsDescribe",
        minWidth: 120
      },
      {
        label: "到货数",
        prop: "numberArrive",
        minWidth: 120
      },
      {
        label: "入库数",
        prop: "numberStore",
        minWidth: 120
      },
      {
        label: "创建时间",
        prop: "createTime",
        minWidth: 160
      }
    ]
  }
})

/**
 * 刷新
 */
const handleRefresh = () => {
  pageModelRef.value.refreshTableData()
}

/**
 * 入库
 */
const handleStore = async (row: any) => {
  await ElMessageBox.confirm("是否确认入库", "入库", {
    type: "warning"
  })
  await processRequest.post("/api/WarehousePurchase/Rk?id=" + row.id)
  ElMessage.success("入库成功")
  handleRefresh()
}
</script>

<template>
  <PageModel ref="pageModelRef" :PageModel="config" @store="handleStore"/>
</template>